package com.future.message.Utils;

import com.future.message.Mapper.UserMapper;
import com.future.message.pojo.Index;
import com.future.message.pojo.RelevantReport;
import com.future.message.pojo.User;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

public class Utils {

    //将字符串src里的内容如：[a,b,c,d]转换为arraylist形势
    public static ArrayList<String> splitAdd(String src) {
        ArrayList<String> ss = new ArrayList<String>();
        String a = "";
        String b = "";
        String[] s1 = src.split("(\\[)");
        for (String s : s1) {
            a = a + s;
        }
        String[] s2 = a.split("]");
        for (String sc : s2) {
            b = b + sc;
        }
        String[] s3 = b.split(", ");//多个空格
        for (String x : s3) {
            ss.add(x);
        }
        return ss;
    }

    //返回已经切割好符号的String字符串[a，b，c]变成 a，b，c
    public static String[] split(String src) {
        ArrayList<String> ss = new ArrayList<String>();
        String a = "";
        String b = "";
        String[] s1 = src.split("(\\[)");
        for (String s : s1) {
            a = a + s;
        }
        String[] s2 = a.split("]");
        for (String sc : s2) {
            b = b + sc;
        }
        String[] s3 = b.split(", ");//多了一个空格
        return s3;
    }
    public static RelevantReport addRelevantReportPojo(Integer userId, Integer firstIndexId, Integer secondIndexId, Integer thirdIndexId) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date1 = simpleDateFormat.format(date);
        RelevantReport relevantReport = new RelevantReport();
        relevantReport.setFirstIndexId(firstIndexId);
        relevantReport.setSecondIndexId(secondIndexId);
        relevantReport.setThirdIndexId(thirdIndexId);
        relevantReport.setUserId(userId);
        relevantReport.setRelevantTime(date1);
        return relevantReport;
    }

    public static Object[] removeDuplicates(Integer[] arr) {
        Set set = new HashSet();
        for(int i=0;i<arr.length;i++){
            set.add(arr[i]);
        }
        return set.toArray();
    }


}
